<?php
namespace Common\Util;
class Mp3info
{
	

	
	public function sb(){
		
		echo "SB ";
		
		
	}

	
	public function GetMp3Lyric($name){
		$search_data=json_decode($this->music_search($name, "1"));
		$musci_id=($search_data->result->songs[0]->id);
		$Lyric=json_decode($this->get_music_lyric($musci_id));
		return $Lyric->lrc->lyric;
	}
	
	
	
	
	
	private function music_search($word, $type){
		$url = "http://music.163.com/api/search/pc";
		$post_data = array(
			's' => $word,
			'offset' => '0',
			'limit' => '20',
			'type' => $type,
		);
		
		return $this->curl_post($url,$post_data);
	}
	private function get_music_lyric($music_id){
		$url = "http://music.163.com/api/song/lyric?os=pc&id=" . $music_id . "&lv=-1&kv=-1&tv=-1";
		return $this->curl_post($url);
	}
	
	
	
	private function curl_post($url,$param){
		$refer = "http://music.163.com/";
		$header[] = "Cookie: " . "appver=1.5.0.75771;";
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
		curl_setopt($ch, CURLOPT_REFERER, $refer);
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param));
		$output = curl_exec($ch);
		curl_close($ch);
		return $output;
	}
	
   
}